package stream;

import org.junit.BeforeClass;
import org.junit.Test;

import java.io.*;
import java.util.*;

/**
 *
 * Created by Robo on 2018/5/21.
 */
public class JunitTestFileLoad {

    static FileInputStream fis;
    @BeforeClass
    public static  void initList(){
        try {
            fis = new FileInputStream("C:\\Users\\acer\\file_test\\createTable.txt");

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        System.out.println("init...");

    }


    @Test//生产线增加前缀后 把建表语句改成 修改表名
    public void bufferTest(){
        Set<String> tbNames = new HashSet<>();
        StringBuilder sb = new StringBuilder();
        String tempLine = "";
        BufferedReader br=new BufferedReader(new InputStreamReader(fis));
        try {
            while((tempLine=br.readLine())!=null){
                if (tempLine.startsWith("create table")) {
                    StringBuilder tb = new StringBuilder();
                    char[] chars = tempLine.toCharArray();
                    for (int i = 0; i < chars.length; i++) {
                        if(Character.isUpperCase(chars[i]) || '_'==chars[i]){
                            tb.append(chars[i]);
                        }
                    }
                    String tbStr = tb.toString();
                    if(tbStr.startsWith("ZX_") || tbStr.startsWith("JC_")){
                        tbNames.add(tbStr);
                    }
//                    sb.append(tempLine);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
//        tbNames.stream().forEach(System.out::println);
        for (String tb : tbNames) {
            String sql = "alter table %s rename to %s;";
            System.out.println(String.format(sql,tb.substring(3),tb));
        }
//        System.out.println(sb.toString());
    }

}
